/*
 * ProgressBar.cpp
 *
 *  Created on: 17/10/2011
 *      Author: diego
 */

#include "ProgressBar.h"

ProgressBar::ProgressBar(int largo) {
	this->largo = largo;
	this->cant_numerales = 0;
	this->string_inicial = "Indexado [";
}

void ProgressBar::iniciar(){
	this->update(0);
}

void ProgressBar::finalizar(){
	this->update(100);
	cout << endl << flush;
}

void ProgressBar::update(int p){
	cout << "\r" << flush;
	this->cant_numerales = (this->largo * p) / 100;
	string s;
	s += this->string_inicial;

	int i;
	for (i = 0; i < this->cant_numerales; i++){
		s += "#";
	}
	for (i = 0; i < (this->largo - this->cant_numerales); i++){
		s += "-";
	}
	s += "] " + toString(p) + "%";
	cout << s << flush;
}

string ProgressBar::toString(int n){
	stringstream Num;
	string str;

	Num << n;

	str = Num.str();

	return str;
}

ProgressBar::~ProgressBar() {

}

